/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Library General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301,  USA
 */

#include "int_sms.h"

void delete_conv_yes(void)
{
	evas_object_del(warn_win);
	Elm_Genlist_Item *item = elm_genlist_selected_item_get(conv_list);
	if (item) {
		_conv *con = (_conv *)elm_genlist_item_data_get(item);
		del_conv(con);
		elm_genlist_item_del(item);
	}
}

void delete_conv_no(void)
{
	evas_object_del(warn_win);
}

void delete_conv(void *data, Evas_Object *obj, void *event_info)
{
	popup_warning ("Are You sure you want", "to delete this Conversation?", delete_conv_yes, delete_conv_no);
}

void my_anchorblock_bt(void *data, Evas_Object *obj, void *event_info)
{
   Evas_Object *av = data;
   elm_anchorblock_hover_end(av);
}

void my_anchorblock_anchor(void *data, Evas_Object *obj, void *event_info)
{
   Evas_Object *av = data;
   Elm_Entry_Anchorblock_Info *ei = event_info;
   Evas_Object *bt, *bx;
   
   bt = elm_button_add(obj);
   elm_button_label_set(bt, ei->name);
   elm_hover_content_set(ei->hover, "middle", bt);
   evas_object_show(bt);

   // hints as to where we probably should put hover contents (buttons etc.).
   if (ei->hover_top)
     {
	bx = elm_box_add(obj);
	bt = elm_button_add(obj);
	elm_button_label_set(bt, "Top 1");
	elm_box_pack_end(bx, bt);
	evas_object_smart_callback_add(bt, "clicked", my_anchorblock_bt, av);
	evas_object_show(bt);
	bt = elm_button_add(obj);
	elm_button_label_set(bt, "Top 2");
	elm_box_pack_end(bx, bt);
	evas_object_smart_callback_add(bt, "clicked", my_anchorblock_bt, av);
	evas_object_show(bt);
	bt = elm_button_add(obj);
	elm_button_label_set(bt, "Top 3");
	elm_box_pack_end(bx, bt);
	evas_object_smart_callback_add(bt, "clicked", my_anchorblock_bt, av);
	evas_object_show(bt);
	elm_hover_content_set(ei->hover, "top", bx);
	evas_object_show(bx);
     }
   if (ei->hover_bottom)
     {
	bt = elm_button_add(obj);
	elm_button_label_set(bt, "Bot");
	elm_hover_content_set(ei->hover, "bottom", bt);
	evas_object_smart_callback_add(bt, "clicked", my_anchorblock_bt, av);
	evas_object_show(bt);
     }
   if (ei->hover_left)
     {
	bt = elm_button_add(obj);
	elm_button_label_set(bt, "Left");
	elm_hover_content_set(ei->hover, "left", bt);
	evas_object_smart_callback_add(bt, "clicked", my_anchorblock_bt, av);
	evas_object_show(bt);
     }
   if (ei->hover_right)
     {
	bt = elm_button_add(obj);
	elm_button_label_set(bt, "Right");
	elm_hover_content_set(ei->hover, "right", bt);
	evas_object_smart_callback_add(bt, "clicked", my_anchorblock_bt, av);
	evas_object_show(bt);
     }
}

void close_win_sms(void *data, Evas_Object *obj, void *event_info)
{
	free(sms_bb);
	evas_object_del(win_sms);
}

void show_reply_bubble(void *data, Evas_Object *obj, void *event_info)
{
    Evas_Object *ic, *en, *bt;
    char buf[255], temp[255];
    static Winlist count_data;
    
	//add an entry in a bubble
	ic = elm_icon_add(win_sms);
	send_bb = elm_bubble_add(win_sms);
	elm_bubble_corner_set(send_bb, "top_right");
	snprintf(buf, sizeof(buf), "%s/sms_write.png", "/usr/share/launcher");
	elm_icon_file_set(ic, buf, NULL);
	elm_icon_scale_set(ic, 1, 1);
	evas_object_size_hint_min_set(ic, 40, 40);
	evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);

   //reply bubble	
	sprintf(temp, "Re:%s", Con_Sms->name);
	elm_bubble_label_set(send_bb, temp);
	elm_bubble_info_set(send_bb, "0");
	elm_bubble_icon_set(send_bb, ic);
	evas_object_show(ic);
	evas_object_size_hint_weight_set(send_bb, 1.0, 0.0);
	evas_object_size_hint_align_set(send_bb, -1.0, 0.0);
	
	en = elm_entry_add(win_sms);
	elm_entry_line_wrap_set(en, 1);
	elm_bubble_content_set(send_bb, en);
	evas_object_show(en);
	count_data.win = send_bb;
	count_data.li = en;
	evas_object_smart_callback_add(en, "changed", update_letter_count, &count_data);		
	elm_box_pack_before(conv_list_vbox, send_bb, conv_list_hbox);
	evas_object_show(send_bb);

    //delete reply_bt
    evas_object_del(reply_bt);

    //add the send button
	bt = elm_button_add(win_sms);
	elm_button_label_set(bt, "Send");
	evas_object_size_hint_weight_set(bt, 1.0, 1.0);
	evas_object_size_hint_align_set(bt, -1.0, -1.0);
	elm_box_pack_start(conv_list_hbox, bt);
	evas_object_show(bt);
	Re.ic = ic;
	Re.en = en;
	Re.from = 0;
	evas_object_smart_callback_add(bt, "clicked", reply_sms, NULL);
}

void conv_list_selected(void *data, Evas_Object *obj, void *event_info)
{
	//show a page with a list of sms from / to this person
	//show entry at bottom and a send button
	Evas_Object *bg, *sc, *bt;
	char *tok, ty[255], temp[255];
	
	//get data from selected item
	Elm_Genlist_Item *item = elm_genlist_selected_item_get(conv_list);
	_conv *con = (_conv *)elm_genlist_item_data_get(item);
	
	win_sms = elm_win_add(NULL, "SMS", ELM_WIN_BASIC);
	elm_win_title_set(win_sms, "Conversation SMS's");
	elm_win_autodel_set(win_sms, 1);

	bg = elm_bg_add(win_sms);
	elm_win_resize_object_add(win_sms, bg);
	evas_object_size_hint_weight_set(bg, 1.0, 1.0);
	evas_object_show(bg);

	//add vbox 
	conv_list_vbox = elm_box_add(win_sms);
	elm_win_resize_object_add(win_sms, conv_list_vbox);
	evas_object_size_hint_weight_set(conv_list_vbox, 1.0, 1.0);
	evas_object_show(conv_list_vbox);
	
	//add a scroller
	sc = elm_scroller_add(win_sms);
	elm_scroller_bounce_set(sc, 0, 0);
	evas_object_size_hint_weight_set(sc, 1.0, 1.0);
	evas_object_size_hint_align_set(sc, -1.0, -1.0);
	elm_box_pack_end(conv_list_vbox, sc);
	evas_object_show(sc);

	//add another vbox
	vbox_sms = elm_box_add(win_sms);
	evas_object_size_hint_weight_set(vbox_sms, 1.0, 1.0);
	elm_scroller_content_set(sc, vbox_sms);
	evas_object_show(vbox_sms);

	//add conversation sms's
	add_conv_sms();

	//add an entry in a bubble
/*	ic = elm_icon_add(win_sms);
	bb = elm_bubble_add(win_sms);
	elm_bubble_corner_set(bb, "top_right");
	snprintf(buf, sizeof(buf), "%s/sms_write.png", "/usr/share/launcher");
	elm_icon_file_set(ic, buf, NULL);
	elm_icon_scale_set(ic, 1, 1);
	evas_object_size_hint_min_set(ic, 40, 40);
	evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);*/

	//set up con_sms
	free (Con_Sms);
	Con_Sms = (_con_sms *) malloc(sizeof(_con_sms) * 1);
	if(strlen(con->name) > 0) strcpy(Con_Sms->name, con->name);
	else {
		strcpy(temp, con->sender);
		if (strchr(temp, ':')) {
			strcpy(ty, temp);
			tok = strtok(ty, ":");
			tok = strtok(NULL, ":");
			strcpy(temp, tok);
		}
		strcpy(Con_Sms->name, temp);
	}
	strcpy(Con_Sms->p_no, con->sender);

   //reply bubble	
/*	sprintf(temp, "Re:%s", Con_Sms->name);
	elm_bubble_label_set(bb, temp);
	elm_bubble_info_set(bb, "0");
	elm_bubble_icon_set(bb, ic);
	evas_object_show(ic);
	evas_object_size_hint_weight_set(bb, 1.0, 0.0);
	evas_object_size_hint_align_set(bb, -1.0, 0.0);
	
	en = elm_entry_add(win_sms);
	elm_entry_line_wrap_set(en, 1);
	elm_bubble_content_set(bb, en);
	evas_object_show(en);
	count_data.win = bb;
	count_data.li = en;
	evas_object_smart_callback_add(en, "changed", update_letter_count, &count_data);		
	elm_box_pack_end(vbox, bb);
	evas_object_show(bb);*/
	
	//add hbox
	conv_list_hbox = elm_box_add(win_sms);
	elm_box_horizontal_set(conv_list_hbox, 1);
	elm_box_homogenous_set(conv_list_hbox, 1);
	evas_object_size_hint_weight_set(conv_list_hbox, 1.0, 0.0);
	evas_object_size_hint_align_set(conv_list_hbox, -1.0, 0.0);
	elm_box_pack_end(conv_list_vbox, conv_list_hbox);
	evas_object_show(conv_list_hbox);

	//add reply button
	reply_bt = elm_button_add(win_sms);
	elm_button_label_set(reply_bt, "Reply");
	evas_object_size_hint_weight_set(reply_bt, 1.0, 1.0);
	evas_object_size_hint_align_set(reply_bt, -1.0, -1.0);
	elm_box_pack_end(conv_list_hbox, reply_bt);
	evas_object_show(reply_bt);
	evas_object_smart_callback_add(reply_bt, "clicked", show_reply_bubble, NULL);

	//add contact button
	bt = elm_button_add(win_sms);
	elm_button_label_set(bt, "Add Cont");
	evas_object_size_hint_weight_set(bt, 1.0, 1.0);
	evas_object_size_hint_align_set(bt, -1.0, -1.0);
	elm_box_pack_end(conv_list_hbox, bt);
	evas_object_show(bt);
	strcpy(con_data.num, con->sender);
	strcpy(con_data.action, "Add to Contacts SMS");
	evas_object_smart_callback_add(bt, "clicked", add_edit_contact, &con_data);

	//add delete button
	bt = elm_button_add(win_sms);
	elm_button_label_set(bt, "Del All");
	evas_object_size_hint_weight_set(bt, 1.0, 1.0);
	evas_object_size_hint_align_set(bt, -1.0, -1.0);
	elm_box_pack_end(conv_list_hbox, bt);
	evas_object_show(bt);
	evas_object_smart_callback_add(bt, "clicked", (void *)delete_conv, conv_list);
	
	//add notification button
	bt = elm_button_add(win_sms);
	elm_button_label_set(bt, "Cancel");
	evas_object_size_hint_weight_set(bt, 1.0, 1.0);
	evas_object_size_hint_align_set(bt, -1.0, -1.0);
	elm_box_pack_end(conv_list_hbox, bt);
	evas_object_show(bt);
	evas_object_smart_callback_add(bt, "clicked", close_win_sms, NULL);
	
	evas_object_resize(win_sms, 640, 480);
	evas_object_show(win_sms);
}

char *conv_label_get(const void *data, Evas_Object *obj, const char *part)
{
	char *ty=NULL, tystr[255], *tok, temp[255];
	_conv *con = (_conv *)data;

	if (!strcmp(part, "elm.text")) {
		if(strlen(con->name) > 0) strcpy(tystr, con->name);
		else {
			strcpy(temp, con->sender);
			if (strchr(temp, ':')) {
				tok = strtok(temp, ":");
				tok = strtok(NULL, ":");
				strcpy(temp, tok);
			}
			strcpy(tystr, temp);
		}
		sprintf(temp, "%s (%d)", tystr, con->count);
		ty = strdup(temp);
	}
	else if (!strcmp(part, "elm.text.sub"))
	{
		if(con->dir == 1) strcpy(tystr, "==>OUT");
		else strcpy(tystr, "IN<==");
		sprintf(temp, "%s     %s", con->timestamp, tystr);
		ty = strdup(temp);
	}
	return (ty);
}

Evas_Object *conv_icon_get(const void *data, Evas_Object *obj, const char *part)
{
	char buf[255];
	Evas_Object *ic = elm_icon_add(obj);
	
	if (!strcmp(part, "elm.swallow.icon")) {
		snprintf(buf, sizeof(buf), "%s/conv.png", "/usr/share/launcher");
		elm_icon_file_set(ic, buf, NULL);
	}
	evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
	return ic;
}

Eina_Bool conv_state_get(const void *data, Evas_Object *obj, const char *part)
{
   return 0;
}

void conv_del (const void *data, Evas_Object *obj)
{
}

void sms_app(void *data, Evas_Object *obj, void *event_info)
{
	Evas_Object *bg, *vbox, *hbox, *bt;
	static Winlist wl;
	
	win_conv = elm_win_add(NULL, "Conv", ELM_WIN_BASIC);
	elm_win_title_set(win_conv, "Conversations");
	elm_win_autodel_set(win_conv, 1);

	bg = elm_bg_add(win_conv);
	elm_win_resize_object_add(win_conv, bg);
	evas_object_size_hint_weight_set(bg, 1.0, 1.0);
	evas_object_show(bg);

	//add vbox 
	vbox = elm_box_add(win_conv);
	elm_win_resize_object_add(win_conv, vbox);
	evas_object_size_hint_weight_set(vbox, 1.0, 1.0);
	evas_object_show(vbox);
	
	//add list to vbox now
	conv_list = elm_genlist_add(win_conv);
	elm_genlist_bounce_set(conv_list, 0, 0);
	evas_object_size_hint_weight_set(conv_list, 1.0, 1.0);
	evas_object_size_hint_align_set(conv_list, -1.0, -1.0);
	elm_genlist_always_select_mode_set(conv_list, 1);
	elm_box_pack_end(vbox, conv_list);
	evas_object_show(conv_list);
	evas_object_smart_callback_add(conv_list, "selected", conv_list_selected, conv_list);

	//genlist class defs
	itc_conv.item_style   		= "double_label";
	itc_conv.func.label_get 	= conv_label_get;
	itc_conv.func.icon_get  	= conv_icon_get;
	itc_conv.func.state_get 	= conv_state_get;
	itc_conv.func.del      		= conv_del;
	
	//add converations
	add_sms_conv();

	//add hbox
	hbox = elm_box_add(win_conv);
	elm_box_homogenous_set(hbox ,1);
	elm_box_horizontal_set(hbox, 1);
	evas_object_size_hint_weight_set(hbox, 1.0, 0.0);
	evas_object_size_hint_align_set(hbox, -1.0, 0.0);
	elm_box_pack_end(vbox, hbox);
	evas_object_show(hbox);

	//add new sms button
	bt = elm_button_add(win_conv);
	elm_button_label_set(bt, "New");
	evas_object_size_hint_weight_set(bt, 1.0, 1.0);
	evas_object_size_hint_align_set(bt, -1.0, -1.0);
	elm_box_pack_end(hbox, bt);
	evas_object_show(bt);
	//strcpy(da.action, "sms_add");
	evas_object_smart_callback_add(bt, "clicked", new_sms, NULL);
	
	//add notification button
	bt = elm_button_add(win_conv);
	elm_button_label_set(bt, "Cancel");
	evas_object_size_hint_weight_set(bt, 1.0, 1.0);
	evas_object_size_hint_align_set(bt, -1.0, -1.0);
	elm_box_pack_end(hbox, bt);
	evas_object_show(bt);
	wl.win = win_conv;
	wl.li = NULL;
	evas_object_smart_callback_add(bt, "clicked", cancel_button_clicked, &wl);
	
	evas_object_resize(win_conv, 480, 640);
	evas_object_show(win_conv);
}

char *sms_rec_label_get(const void *data, Evas_Object *obj, const char *part)
{
	char *ty=NULL;
	_con_sms *con = (_con_sms *)data;

	ty = strdup(con->name);
	return (ty);
}

Evas_Object *sms_rec_icon_get(const void *data, Evas_Object *obj, const char *part)
{
	/*char buf[255];
	Evas_Object *ic = elm_icon_add(obj);
	
	if (!strcmp(part, "elm.swallow.icon")) {
		snprintf(buf, sizeof(buf), "%s/conv.png", "/usr/share/launcher");
		elm_icon_file_set(ic, buf, NULL);
	}
	evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
	return ic;*/
	return NULL;
}

Eina_Bool sms_rec_state_get(const void *data, Evas_Object *obj, const char *part)
{
   return 0;
}

void sms_rec_del (const void *data, Evas_Object *obj)
{
}

void new_sms(void *data, Evas_Object *obj, void *event_info)
{
	//show entry at bottom and a send button
	Evas_Object *bg, *vbox, *bt, *hbox, *ic, *bb, *en, *lb, *vbox1, *g_vbox;
	static Winlist wl, count_data;
	char buf[255];
	_act_element *da = (_act_element *)data;

	win_new_sms = elm_win_add(NULL, "SMS", ELM_WIN_BASIC);
	elm_win_title_set(win_new_sms, "Send SMS");
	elm_win_autodel_set(win_new_sms, 1);

	//add background
	bg = elm_bg_add(win_new_sms);
	elm_win_resize_object_add(win_new_sms, bg);
	evas_object_size_hint_weight_set(bg, 1.0, 1.0);
	evas_object_show(bg);

	//add vbox 
	vbox = elm_box_add(win_new_sms);
	elm_win_resize_object_add(win_new_sms, vbox);
	evas_object_size_hint_weight_set(vbox, 1.0, 1.0);
	evas_object_show(vbox);
	
	//add a label
	lb = elm_label_add(win_new_sms);
	elm_label_label_set(lb, " Send To: ");
	elm_box_pack_end(vbox, lb);
	evas_object_show(lb);

	//add hbox
	hbox = elm_box_add(win_new_sms);
	elm_box_horizontal_set(hbox, 1);
	evas_object_size_hint_weight_set(hbox, 1.0, 0.0);
	evas_object_size_hint_align_set(hbox, -1.0, 0.0);
	elm_box_pack_end(vbox, hbox);
	evas_object_show(hbox);

	//add a vbox for the list 
	g_vbox = elm_box_add(win_new_sms);
	evas_object_size_hint_weight_set(g_vbox, 1.0, 1.0);
	evas_object_size_hint_align_set(g_vbox, -1.0, -1.0);
	elm_box_pack_end(hbox, g_vbox);
	evas_object_show(g_vbox);

	//add a vbox for the buttons
	vbox1 = elm_box_add(win_new_sms);
	elm_box_homogenous_set(vbox1, 1);	
	elm_box_pack_end(hbox, vbox1);
	evas_object_show(vbox1);
	
	//add a genlist for contact names
	sms_rec_list = elm_genlist_add(win_new_sms);
	elm_genlist_bounce_set(sms_rec_list, 0, 0);
	evas_object_size_hint_weight_set(sms_rec_list, 1.0, 1.0);
	evas_object_size_hint_align_set(sms_rec_list, -1.0, -1.0);
	elm_genlist_multi_select_set(sms_rec_list, 1);
	elm_box_pack_end(g_vbox, sms_rec_list);
	evas_object_show(sms_rec_list);
	//evas_object_smart_callback_add(sms_rec_list, "selected", sms_rec_list_selected, conv_list);

	//genlist class defs
	itc_sms_rec.item_style   	= "default";
	itc_sms_rec.func.label_get 	= sms_rec_label_get;
	itc_sms_rec.func.icon_get  	= sms_rec_icon_get;
	itc_sms_rec.func.state_get 	= sms_rec_state_get;
	itc_sms_rec.func.del      	= sms_rec_del;

	//set up con_sms
	free (Con_Sms);
	Con_Sms = (_con_sms *) malloc(sizeof(_con_sms) * 1);
	
	//if we've come here as an action followup, add details to the list
	if (da) {
		strcpy(Con_Sms[0].name, da->name);
		strcpy(Con_Sms[0].p_no, da->num);
		elm_genlist_item_append(sms_rec_list, &itc_sms_rec, &Con_Sms[0], NULL, 
			ELM_GENLIST_ITEM_NONE, NULL, NULL);
	}
	else strcpy(Con_Sms[0].p_no, "none"); //caters for send without phone no
	
	//add button to select contacts
	bt = elm_button_add(win_new_sms);
	elm_button_label_set(bt, "Add Contact");
	evas_object_size_hint_weight_set(bt, 1.0, 1.0);
	evas_object_size_hint_align_set(bt, -1.0, -1.0);
	elm_box_pack_end(vbox1, bt);
	evas_object_show(bt);
	strcpy(con_val, "select"); //to tell int contacts app to select contacts
	evas_object_smart_callback_add(bt, "clicked", contacts_app, con_val);

	//add button to add a number
	bt = elm_button_add(win_new_sms);
	elm_button_label_set(bt, "Add Number");
	evas_object_size_hint_weight_set(bt, 1.0, 1.0);
	evas_object_size_hint_align_set(bt, -1.0, -1.0);
	elm_box_pack_end(vbox1, bt);
	evas_object_show(bt);
	evas_object_smart_callback_add(bt, "clicked", get_sms_user_num, sms_rec_list);

	//add button to delete selected line from sms_rec_list
	bt = elm_button_add(win_new_sms);
	elm_button_label_set(bt, "Delete");
	evas_object_size_hint_weight_set(bt, 1.0, 1.0);
	evas_object_size_hint_align_set(bt, -1.0, -1.0);
	elm_box_pack_end(vbox1, bt);
	evas_object_show(bt);
	evas_object_smart_callback_add(bt, "clicked", del_sel_sms_con, sms_rec_list);
	
	//add an entry in a bubble
	ic = elm_icon_add(win_new_sms);
	bb = elm_bubble_add(win_new_sms);
	elm_bubble_corner_set(bb, "top_right");
	snprintf(buf, sizeof(buf), "%s/sms_write.png", "/usr/share/launcher");
	elm_icon_file_set(ic, buf, NULL);
	elm_icon_scale_set(ic, 1, 1);
	evas_object_size_hint_min_set(ic, 40, 40);
	evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);

	elm_bubble_info_set(bb, "0");
	elm_bubble_icon_set(bb, ic);
	evas_object_show(ic);
	evas_object_size_hint_weight_set(bb, 1.0, 1.0);
	evas_object_size_hint_align_set(bb, -1.0, -1.0);
	
	en = elm_entry_add(win_new_sms);
	elm_entry_line_wrap_set(en, 1);
	elm_object_focus(en);
	elm_bubble_content_set(bb, en);
	evas_object_show(en);
	count_data.win = bb;
	count_data.li = en;
	evas_object_smart_callback_add(en, "changed", update_letter_count, &count_data);	
	elm_box_pack_end(vbox, bb);
	evas_object_show(bb);
	
	//add hbox
	hbox = elm_box_add(win_new_sms);
	elm_box_homogenous_set(hbox ,1);
	elm_box_horizontal_set(hbox, 1);
	evas_object_size_hint_weight_set(hbox, 1.0, 0.0);
	evas_object_size_hint_align_set(hbox, -1.0, 0.0);
	elm_box_pack_end(vbox, hbox);
	evas_object_show(hbox);

	//add reply button
	bt = elm_button_add(win_new_sms);
	elm_button_label_set(bt, "Send");
	evas_object_size_hint_weight_set(bt, 1.0, 1.0);
	evas_object_size_hint_align_set(bt, -1.0, -1.0);
	elm_box_pack_end(hbox, bt);
	evas_object_show(bt);
	Re.ic = ic;
	Re.en = en;
	Re.from = 1;
	evas_object_smart_callback_add(bt, "clicked", (void *)reply_sms, NULL);

	//add cancel button
	bt = elm_button_add(win_new_sms);
	elm_button_label_set(bt, "Cancel");
	evas_object_size_hint_weight_set(bt, 1.0, 1.0);
	evas_object_size_hint_align_set(bt, -1.0, -1.0);
	elm_box_pack_end(hbox, bt);
	evas_object_show(bt);
	wl.win = win_new_sms;
	wl.li = NULL;
	evas_object_smart_callback_add(bt, "clicked", cancel_button_clicked, &wl);
	
	evas_object_resize(win_new_sms, 480, 640);
	evas_object_show(win_new_sms);
}

void get_sms_user_num(void *data, Evas_Object *obj, void *event_info)
{
	Evas_Object *bg, *inwin, *vbox, *lb, *get_num_win, *bt, *en, *hbox;
	static Winlist wl;
	
	get_num_win = elm_win_add(NULL, "inwin", ELM_WIN_DIALOG_BASIC);
	elm_win_title_set(get_num_win, "Enter Phone Number");
	elm_win_autodel_set(get_num_win, 1);

	bg = elm_bg_add(get_num_win);
	elm_win_resize_object_add(get_num_win, bg);
	evas_object_size_hint_weight_set(bg, 1.0, 1.0);
	evas_object_show(bg);

	inwin = elm_win_inwin_add(get_num_win);
	elm_object_style_set(inwin, "minimal_vertical");
	evas_object_show(inwin);

	vbox = elm_box_add(get_num_win);
	elm_win_inwin_content_set(inwin, vbox);
	evas_object_show(vbox);

	//add hbox
	hbox = elm_box_add(get_num_win);
	elm_box_horizontal_set(hbox, 1);
	evas_object_size_hint_weight_set(hbox, 1.0, 0.0);
	evas_object_size_hint_align_set(hbox, -1.0, 0.0);
	elm_box_pack_end(vbox, hbox);
	evas_object_show(hbox);
	
	lb = elm_label_add(get_num_win);
	elm_label_label_set(lb, "Num :");
	elm_box_pack_end(hbox, lb);
	evas_object_show(lb);

	en = elm_entry_add(get_num_win);
	elm_entry_single_line_set(en, 1);
	elm_box_pack_end(hbox, en);
	evas_object_show(en);	
		
	//add close button
	bt = elm_button_add(get_num_win);
	elm_button_label_set(bt, "Done");
	evas_object_size_hint_weight_set(bt, 1.0, 1.0);
	evas_object_size_hint_align_set(bt, 0.5, -1.0);
	elm_box_pack_end(vbox, bt);
	evas_object_show(bt);
	wl.win = get_num_win;
	wl.li = en; //hack: send evas object entry to get the number 
	evas_object_smart_callback_add(bt, "clicked", add_sms_num, &wl);
	
	evas_object_resize(get_num_win, 480, 640);
	evas_object_show(get_num_win);
}

void add_sms_num(void *data, Evas_Object *obj, void *event_info)
{
	Winlist *wl = data;
	int i;
	
	//increment the list count
	count_sms_con ++;
	//realloc the dynamic array
	Con_Sms = (_con_sms *) realloc(Con_Sms, sizeof(_con_sms) * count_sms_con);
	//readd the values to the list
	elm_genlist_clear(sms_rec_list);
	for(i=0; i< count_sms_con-1; i++) {
		elm_genlist_item_append(sms_rec_list, &itc_sms_rec, &Con_Sms[i], NULL, 
			ELM_GENLIST_ITEM_NONE, NULL, NULL);
	}
	i = count_sms_con-1;
	sprintf(Con_Sms[i].name, "%s", elm_entry_entry_get(wl->li));
	sprintf(Con_Sms[i].p_no, "%s", elm_entry_entry_get(wl->li));
	elm_genlist_item_append(sms_rec_list, &itc_sms_rec, &Con_Sms[i], NULL, 
		ELM_GENLIST_ITEM_NONE, NULL, NULL);
	//close the window
	evas_object_del(wl->win);
}
